package gunfire.cards;

import basemod.abstracts.CustomCard;
import com.megacrit.cardcrawl.actions.common.*;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.WeakPower;
import gunfire.GunfireMod;
import gunfire.characters.Taizi;

import static gunfire.GunfireMod.makeCardPath;

public class FrenziedShark extends CustomCard {

    public static final String ID = GunfireMod.makeID(FrenziedShark.class.getSimpleName());
    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG = makeCardPath("FrenziedShark.png");
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardType TYPE = CardType.SKILL;
    private static final CardTarget TARGET = CardTarget.ENEMY;
    public static final CardColor COLOR = Taizi.Enums.COLOR_GRAY;
    private static final int COST = 1;

    public FrenziedShark() {
        super(ID, NAME, IMG, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET);
        this.baseBlock = 3;
        this.exhaust = true;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgradeName();
            this.upgradeBlock(2);
        }
    }

    @Override
    public void triggerOnGlowCheck() {
        this.glowColor = AbstractCard.BLUE_BORDER_GLOW_COLOR.cpy();
        for (AbstractMonster m : AbstractDungeon.getCurrRoom().monsters.monsters) {
            if (!m.isDeadOrEscaped() && m.hasPower("Weakened")) {
                this.glowColor = AbstractCard.GOLD_BORDER_GLOW_COLOR.cpy();
                break;
            }
        }
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        if (!m.isDeadOrEscaped() && m.hasPower("Weakened")){
            this.addToBot(new ApplyPowerAction(m, p, new WeakPower(m, 1, false), 1));
            this.addToBot(new GainBlockAction(p, p, this.block));
        }
        this.addToBot(new ApplyPowerAction(m, p, new WeakPower(m, 1, false), 1));
        this.addToBot(new GainBlockAction(p, p, this.block));
        AbstractCard c = this.makeCopy();
        if(this.upgraded){
            c.upgrade();
        }
        this.addToBot(new MakeTempCardInHandAction(c, 1, false));
    }

    @Override
    public AbstractCard makeCopy() {
        return new FrenziedShark();
    }
}
